package com.zhentao.controller;

import com.zhentao.pojo.Subjects;
import com.zhentao.service.SubjectsService;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class StudjectsController {

    @Autowired
    private Configuration configuration;
    @Resource
    private SubjectsService subjectsService;

    @ResponseBody
    @RequestMapping("/studjects")
    public String getSutJects() throws IOException, TemplateException {
        Template template = configuration.getTemplate("02.ftl");

        List<Subjects> subjects = subjectsService.list();

        Map<String, Object> map = new HashMap<>();
        map.put("subs", subjects);
        template.process(map, new FileWriter("E://11.html"));
        return "OK";
    }



}
